import javax.microedition.rms.RecordStore;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;

final class RecordManager
        implements inf_m {

    private MainThread mainThread;
    private cls_ab M;
    boolean a;
    boolean b;
    boolean c;
    int d;
    int e;
    int f;
    int g;
    String h;
    String i;
    String language;
    int k[];
    int l[];
    int fld_m_int_Array[];
    int n[];
    String o[];
    String p[];
    boolean q;
    boolean r;
    boolean s;
    boolean t;
    int u;
    String v;
    String persona;
    String x;
    String y;
    String z;
    String A;
    String httpURL;
    String deviceID;
    String carrierCountryID;
    String E;
    String phoneNumber;
    String G;
    String H;
    boolean I;
    boolean J;
    boolean K;

    RecordManager(MainThread thread) {
        mainThread = thread;
        M = thread.L;
        A = "";
        E = "";
        G = "0";
        httpURL = Spore.mainThreadImpl.sporeInstance.getAppProperty("httpURL");
        if (httpURL != null && httpURL.toLowerCase().equals("invalid")) {
            httpURL = null;
        }
        String s1 = Spore.mainThreadImpl.sporeInstance.getAppProperty("dropArena");
        mainThread.aR = s1 != null && s1.equals("true");
        s1 = Spore.mainThreadImpl.sporeInstance.getAppProperty("connected");
        mainThread.aW = httpURL != null && s1 != null && s1.equals("true");
        if (!mainThread.aW)
            mainThread.enableTAF = false;
        deviceID = Spore.mainThreadImpl.sporeInstance.getAppProperty("DeviceID");
        carrierCountryID = Spore.mainThreadImpl.sporeInstance.getAppProperty("CarrierCountryID");
        mainThread.websiteURL = Spore.mainThreadImpl.sporeInstance.getAppProperty("WebsiteURL");
        if (httpURL == null)
            mainThread.aW = false;
    }

    final boolean savePrefs() {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        DataOutputStream dout = new DataOutputStream(bout);
        if (h == null) {
            h = mainThread.cA != null ? mainThread.cA : "";
        }
        if (i == null) {
            i = mainThread.cA != null ? mainThread.cA : "";
        }
        try {
            dout.writeBoolean(b);
            dout.writeBoolean(c);
            dout.writeByte(d);
            dout.writeByte(e);
            dout.writeInt(f);
            dout.writeInt(g);
            dout.writeBoolean(q);
            dout.writeBoolean(r);
            dout.writeInt(u);
            dout.writeBoolean(s);
            dout.writeBoolean(t);
            dout.writeBoolean(I);
            dout.writeBoolean(K);
            byte data[] = bout.toByteArray();
            RecordStore rs = RecordStore.openRecordStore("prefs.sav", true);
            if ((rs).getNumRecords() == 0) {
                rs.addRecord(data, 0, data.length);
            } else {
                rs.setRecord(1, data, 0, data.length);
            }
            rs.closeRecordStore();
            return true;
        } catch (Exception ex) {
        }
        return false;
    }

    final boolean loadPrefs() {
        RecordStore recordstore;
        try {
            recordstore = RecordStore.openRecordStore("prefs.sav", true);
            if (recordstore.getNumRecords() == 0) {
                try {
                    recordstore.closeRecordStore();
                }
                catch (Exception _ex) {
                }
                return false;
            }
            byte abyte0[] = recordstore.getRecord(1);
            ByteArrayInputStream bin = new ByteArrayInputStream(abyte0);
            DataInputStream din = new DataInputStream(bin);
            b = din.readBoolean();
            c = din.readBoolean();
            d = din.readByte();
            e = din.readByte();
            f = din.readInt();
            g = din.readInt();
            h = "";
            i = "";
            q = din.readBoolean();
            r = din.readBoolean();
            u = din.readInt();
            s = din.readBoolean();
            t = din.readBoolean();
            language = "";
            H = "";
            persona = "";
            x = "";
            z = "";
            I = din.readBoolean();
            K = din.readBoolean();
            A = "";
            E = "";
            G = "";
            if (G.length() == 0)
                G = "0";
            try {
                recordstore.closeRecordStore();
            }
            catch (Exception _ex) {
            }
            return true;
        } catch (Exception ex) {
        }
        return false;
    }

    final void resetPrefs() {
        M.d();
        a = false;
        b = true;
        c = false;
        d = 0;
        e = 0;
        f = 0;
        g = 0;
        h = mainThread.cA;
        i = mainThread.cA;
        q = false;
        r = false;
        s = false;
        t = false;
        u = 5;
        persona = "";
        x = "";
        y = "";
        z = "";
        H = "";
        I = false;
        K = false;
        J = false;
    }

    final void saveStats() {
        try {
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            DataOutputStream dout = new DataOutputStream(bout);
            dout.writeUTF(v);
            for (int i1 = 0; i1 < 6; i1++)
                dout.writeInt(k[i1]);

            for (int j1 = 0; j1 < 10; j1++) {
                dout.writeInt(n[j1]);
                dout.writeUTF(p[j1]);
            }

            for (int k1 = 0; k1 < 7; k1++)
                dout.writeInt(l[k1]);

            for (int l1 = 0; l1 < 10; l1++) {
                dout.writeInt(fld_m_int_Array[l1]);
                dout.writeUTF(o[l1]);
            }

            byte data[] = bout.toByteArray();
            RecordStore rs = RecordStore.openRecordStore("stats.sav", true);
            if (rs.getNumRecords() == 0)
                rs.addRecord(data, 0, data.length);
            else
                rs.setRecord(1, data, 0, data.length);
            rs.closeRecordStore();
        }
        catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    final boolean e() {
        return loadStats(false);
    }

    final boolean loadStats(boolean flag) {
        try {
            RecordStore rs = RecordStore.openRecordStore("stats.sav", true);
            if (rs.getNumRecords() == 0) {
                return false;
            }
            byte data[] = rs.getRecord(1);
            ByteArrayInputStream bin = new ByteArrayInputStream(data);
            DataInputStream din = new DataInputStream(bin);
            v = din.readUTF();
            if (!flag) {
                k = new int[6];
            }
            for (int i1 = 0; i1 < 6; i1++) {
                if (!flag) {
                    k[i1] = din.readInt();
                } else {
                    din.readInt();
                }
            }
            n = new int[10];
            p = new String[10];
            for (int j1 = 0; j1 < 10; j1++) {
                n[j1] = din.readInt();
                p[j1] = din.readUTF();
            }

            if (!flag) {
                l = new int[7];
            }
            for (int k1 = 0; k1 < 7; k1++) {
                if (!flag) {
                    l[k1] = din.readInt();
                } else {
                    din.readInt();
                }
            }
            fld_m_int_Array = new int[10];
            o = new String[10];
            for (int l1 = 0; l1 < 10; l1++) {
                fld_m_int_Array[l1] = din.readInt();
                o[l1] = din.readUTF();
            }

            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return false;
    }

    final int a(int i1, int j1) {
        if (i1 <= 0) {
            return -1;
        }
        if (j1 == 0) {
            for (j1 = 0; j1 < 10; j1++) {
                if (i1 >= n[j1]) {
                    for (int k1 = 9; k1 > j1; k1--) {
                        n[k1] = n[k1 - 1];
                        p[k1] = p[k1 - 1];
                    }
                    n[j1] = i1;
                    p[j1] = "...";
                    return j1;
                } else {
                    for (j1 = 0; j1 < 10; j1++) {
                        if (i1 >= fld_m_int_Array[j1]) {
                            for (int l1 = 9; l1 > j1; l1--) {
                                fld_m_int_Array[l1] = fld_m_int_Array[l1 - 1];
                                o[l1] = o[l1 - 1];
                            }
                            fld_m_int_Array[j1] = i1;
                            o[j1] = "...";
                            return j1;
                        }
                    }
                }
            }
        }
        return -1;
    }

    final void a(int i1) {
        if (i1 == 0 || i1 == 2) {
            for (int j1 = 0; j1 < k.length; j1++) {
                k[j1] = 0;
            }

        }
        if (i1 == 1 || i1 == 2) {
            for (int k1 = 0; k1 < l.length; k1++) {
                l[k1] = 0;
            }

        }
        if (i1 == 2) {
            v = "";
            fld_m_int_Array = new int[10];
            for (int l1 = 0; l1 < 10; l1++) {
                fld_m_int_Array[l1] = 0;
                o[l1] = "...";
                n[l1] = 0;
                p[l1] = "...";
            }

        }
        saveStats();
    }

    final void a(int i1, int j1, int k1) {
        int l1 = 0;
        if (mainThread.R == 0) {
            if (i1 == 2) {
                if (j1 > k[i1]) {
                    k[i1] = j1;
                    l1 = j1 * 10;
                }
            } else {
                k[i1] += j1;
                if (i1 == 0) {
                    l1 = k1;
                } else if (i1 == 3) {
                    l1 = 30;
                }
            }
            k[5] += l1;
            return;
        }
        if (mainThread.R == 1) {
            if (i1 == 0) {
                l[i1] = j1;
            } else {
                l[i1] += j1;
            }
            if (i1 == 3) {
                l1 = inf_m.ad[k1 - 38];
            } else if (i1 == 1) {
                l1 = 10;
            }
            l[6] += l1;
        }
    }

    final void f() {
        k = new int[6];
        l = new int[7];
        fld_m_int_Array = new int[10];
        o = new String[10];
        n = new int[10];
        p = new String[10];
        a(2);
    }

    final void g() {
        try {
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            DataOutputStream dout = new DataOutputStream(bout);
            dout.writeByte(1);
            int sz = mainThread.co.size();
            dout.writeShort(sz);
            for (int i1 = 0; i1 < sz; i1++) {
                String s1 = (String) mainThread.co.elementAt(i1);
                int j1 = ((Integer) mainThread.cp.elementAt(i1)).intValue();
                dout.writeUTF(s1);
                dout.writeInt(j1);
            }

            byte abyte0[] = bout.toByteArray();
            RecordStore recordstore;
            if (mainThread.aW) {
                recordstore = RecordStore.openRecordStore("cell_con.sav", true);
            } else {
                recordstore = RecordStore.openRecordStore("cell_loc.sav", true);
            }
            if (recordstore.getNumRecords() == 0) {
                recordstore.addRecord(abyte0, 0, abyte0.length);
            } else {
                recordstore.setRecord(1, abyte0, 0, abyte0.length);
            }
            recordstore.closeRecordStore();
            return;
        }
        catch (Exception exception) {
            return;
        }
    }

    final boolean h() {
        Object obj;
        try {
            if (mainThread.aW) {
                obj = RecordStore.openRecordStore("cell_con.sav", true);
            } else {
                obj = RecordStore.openRecordStore("cell_loc.sav", true);
            }
            if (((RecordStore) (obj)).getNumRecords() == 0) {
                return false;
            }
            byte abyte0[] = ((RecordStore) (obj)).getRecord(1);
            ByteArrayInputStream babyte0 = new ByteArrayInputStream(abyte0);
            DataInputStream dabyte0 = new DataInputStream(babyte0);
            if ((dabyte0).readByte() == 0) {
                return false;
            }
            short word0 = dabyte0.readShort();
            for (int i1 = 0; i1 < word0; i1++) {
                mainThread.co.addElement(dabyte0.readUTF());
                mainThread.cp.addElement(new Integer(dabyte0.readInt()));
            }

            return true;
        } catch (Exception rse) {
            rse.printStackTrace();
        }
        return false;
    }
}